<template>
  <div class="box-main">
    <a-spin class="spinning" :spinning="spinning">
      <div class="bax-main-content">
        <div class="header">
          <div class="servicePeople">
            <div class="title">
              <p />
              <p>我的服务人数统计</p>
            </div>
            <div class="listWrap">
              <div class="item">
                <img class="img" src="@/assets/dataStatistics/1.png" alt="" />
                <p>
                  <span>服务总人数</span>
                  <!-- <a-tooltip placement="topLeft">
                    <template #title> 服务总人数服务总人数服务总人数 </template>
                    <QuestionCircleOutlined />
                  </a-tooltip> -->
                </p>
                <a-statistic :value="serviceCount" />
              </div>
              <div class="item">
                <img class="img" src="@/assets/dataStatistics/2.png" alt="" />
                <p>
                  <span>在管人数</span>
                </p>
                <a-statistic :value="managedPeopleCount" />
              </div>
            </div>
          </div>
          <div class="servicePeople">
            <div class="title">
              <p />
              <p>我的服务统计</p>
              <a-range-picker
                v-model:value="serviceTime"
                :format="dateFormat"
                @change="handleCalendarChange"
              />
            </div>
            <div class="listWrap">
              <div class="item">
                <img class="img updateImg" src="@/assets/dataStatistics/3.png" alt="" />
                <p>
                  <span>更新方案人数</span>
                </p>
                <a-statistic :value="updatePlanCount" />
              </div>
              <div class="item">
                <img class="img updateImg" src="@/assets/dataStatistics/4.png" alt="" />
                <p>
                  <span>健康咨询人数</span>
                </p>
                <a-statistic :value="hepImMessageRecordService" />
              </div>
            </div>
          </div>
        </div>
        <div class="executeContent">
          <div class="executeWrap">
            <div class="title">
              <p />
              <p>健康任务执行统计</p>
              <a-range-picker
                v-model:value="serviceTimeTwo"
                :format="dateFormat"
                @change="handleCalendarChangeTwo"
                :disabledDate="disabledDate"
              />
            </div>
            <div class="executeList">
              <div class="item">
                <img class="img" src="@/assets/dataStatistics/5.png" alt="" />
                <p>
                  <span>{{ allExecute.num }}/{{ allExecute.numAll }}</span>
                  <span>健康任务总执行数</span>
                </p>
              </div>
              <div class="item">
                <img class="img" src="@/assets/dataStatistics/6.png" alt="" />
                <p>
                  <span
                    ><i>{{ allExecute.rate }}</i
                    ><i>%</i></span
                  >
                  <span>健康任务总执行率</span>
                </p>
              </div>
            </div>
            <div class="list">
              <div class="item" v-for="(item, index) in list" :key="index">
                <div class="top">
                  <img
                    v-if="item.type == 'PRESCRIPTION'"
                    class="img"
                    src="@/assets/dataStatistics/7.png"
                    alt=""
                  />

                  <img
                    v-else-if="item.type == 'FOLLOW_UP'"
                    class="img"
                    src="@/assets/dataStatistics/9.png"
                    alt=""
                  />
                  <img
                    v-else-if="item.type == 'MONITOR'"
                    class="img"
                    src="@/assets/dataStatistics/10.png"
                    alt=""
                  />
                  <img
                    v-else-if="item.type == 'MEDICATION'"
                    class="img"
                    src="@/assets/dataStatistics/11.png"
                    alt=""
                  />
                  <img
                    v-else-if="item.type == 'VISIT'"
                    class="img"
                    src="@/assets/dataStatistics/12.png"
                    alt=""
                  />
                  <img
                    v-else-if="item.type == 'DIET'"
                    class="img"
                    src="@/assets/dataStatistics/13.png"
                    alt=""
                  />
                  <img
                    v-else-if="item.type == 'SPORT'"
                    class="img"
                    src="@/assets/dataStatistics/14.png"
                    alt=""
                  />
                  <img v-else class="img" src="@/assets/dataStatistics/8.png" alt="" />
                  <p>{{ item.name }}</p>
                </div>
                <div class="min">
                  <p>
                    <span
                      >{{ item.count1 ? item.count1 : 0 }}/{{ item.count2 ? item.count2 : 0 }}</span
                    >
                    <span>执行数</span>
                  </p>
                  <p>
                    <span>{{ item.count3 ? item.count3 : 0 }}%</span>
                    <span>执行率</span>
                  </p>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </a-spin>
  </div>
</template>
<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue'
import { QuestionCircleOutlined } from '@ant-design/icons-vue'
import { getManagedPeopleCount, getUpdatePlanCount, statisticsInfo } from '@/api/dataStatistics'
import { message } from 'ant-design-vue'
// import * as echarts from 'echarts'
import { useRouter, useRoute } from 'vue-router'
import store from '@/store'
import dayjs, { Dayjs } from 'dayjs'
const dateFormat = 'YYYY/MM/DD'
const route = useRoute()
const router = useRouter()
const serviceTime = ref([])
const serviceTimeTwo = ref([])
const list = ref([])
const spinning = ref(false)
const serviceCount = ref(0)
const managedPeopleCount = ref(0)
const updatePlanCount = ref(0)
const hepImMessageRecordService = ref(0)
const serviceTimeObj = ref({
  buyTimeSta: '',
  buyTimeEnd: '',
  buyTimeStaTwo: '',
  buyTimeEndTwo: ''
})
const allExecute = ref({
  num: 0,
  numAll: 0,
  rate: 0
})
onMounted(() => {
  //   serviceCount.value = 0
  //   managedPeopleCount.value = 0
  //   updatePlanCount.value = 0
  //   hepImMessageRecordService.value = 0
  spinning.value = true
  getManagedPeopleCountFun()
  //   diseaseLite.value = []
  //   if (store.userApp.permissionList.indexOf('hp-admin:warningCenter:serviceNotification') != -1) {
  //     diseaseLite.value.push('服务通知')
  //   }
  //   if (store.userApp.permissionList.indexOf('hp-admin:warningCenter:outpatientService') != -1) {
  //     diseaseLite.value.push('门诊')
  //   }
  //   默认回显日期
  //   serviceTime.value = [dayjs('2024/06/06', dateFormat), dayjs('2024/10/25', dateFormat)]
  //   serviceTimeTwo.value = [dayjs('2024/07/03', dateFormat), dayjs('2024/12/20', dateFormat)]
  getUpdatePlanCountFun('init')
  statisticsInfoFun()
})

const getManagedPeopleCountFun = (name) => {
  getManagedPeopleCount({
    type: 'self'
  })
    .then((res) => {
      serviceCount.value = res.data && res.data.serviceCount ? res.data.serviceCount : 0
      managedPeopleCount.value =
        res.data && res.data.managedPeopleCount ? res.data.managedPeopleCount : 0
    })
    .catch(() => {})
}
const getUpdatePlanCountFun = (name) => {
  getUpdatePlanCount({
    type: 'self',
    startDate: serviceTimeObj.value.buyTimeSta ? serviceTimeObj.value.buyTimeSta : '',
    endDate: serviceTimeObj.value.buyTimeEnd ? serviceTimeObj.value.buyTimeEnd : ''
  })
    .then((res) => {
      if (name != 'init') {
        spinning.value = false
      }
      updatePlanCount.value = res.data && res.data.updatePlanCount ? res.data.updatePlanCount : 0
      hepImMessageRecordService.value =
        res.data && res.data.hepImMessageRecordService ? res.data.hepImMessageRecordService : 0
    })
    .catch(() => {
      if (name != 'init') {
        spinning.value = false
      }
    })
}
const statisticsInfoFun = () => {
  statisticsInfo({
    type: 'self',
    startDate: serviceTimeObj.value.buyTimeStaTwo ? serviceTimeObj.value.buyTimeStaTwo : '',
    endDate: serviceTimeObj.value.buyTimeEndTwo ? serviceTimeObj.value.buyTimeEndTwo : ''
  })
    .then((res) => {
      spinning.value = false
      allExecute.value.num = res.data && res.data.count1 ? res.data.count1 : 0
      allExecute.value.numAll = res.data && res.data.count2 ? res.data.count2 : 0
      allExecute.value.rate = res.data && res.data.count3 ? res.data.count3 : 0
      const listWrap = res.data && res.data.list && res.data.list.length > 0 ? res.data.list : []
      if (listWrap && listWrap.length > 0) {
        for (let i = 0; i < listWrap.length; i++) {
          listWrap[i].count3 =
            parseFloat(Number(listWrap[i].count3)) == 0 ? 0 : parseFloat(Number(listWrap[i].count3))
        }
        list.value = listWrap
      } else {
        list.value = []
      }
    })
    .catch(() => {
      spinning.value = false
    })
}
const handleCalendarChange = (values) => {
  spinning.value = true
  serviceTimeObj.value.buyTimeSta = values && values[0] ? dayjs(values[0]).format('YYYY-MM-DD') : ''
  serviceTimeObj.value.buyTimeEnd = values && values[1] ? dayjs(values[1]).format('YYYY-MM-DD') : ''
  getUpdatePlanCountFun()
}
const handleCalendarChangeTwo = (values) => {
  //   console.log('日期选择发生变化')
  //   console.log(values)
  //   console.log(serviceTime.value)
  spinning.value = true
  serviceTimeObj.value.buyTimeStaTwo =
    values && values[0] ? dayjs(values[0]).format('YYYY-MM-DD') : ''
  serviceTimeObj.value.buyTimeEndTwo =
    values && values[1] ? dayjs(values[1]).format('YYYY-MM-DD') : ''
  statisticsInfoFun()
}
const disabledDate = (current) => {
  // 禁用当前日期之后的日期
  return current && current > dayjs().startOf('day').toDate()
}
</script>
<style lang="less" scoped>
.box-main {
  width: 100%;
  height: 100%;
  padding: 16px;
  overflow: hidden !important;
  background: #f5f5f5;

  ::v-deep(.ant-spin-nested-loading) {
    height: 100%;

    .ant-spin-container {
      height: 100%;
    }
  }

  .bax-main-content {
    width: 100%;
    height: 100%;
    overflow: hidden !important;

    .header {
      .servicePeople {
        display: inline-block;
        width: calc(50% - 8px);
        height: 250px;
        padding: 24px;
        vertical-align: middle;
        background: #fff;
        border-radius: 8px;

        &:nth-child(1) {
          margin-right: 16px;
        }

        .title {
          position: relative;
          font-size: 0;

          p {
            display: inline-block;
            margin: 0;
            font-size: 18px;
            font-weight: 700;
            color: #1d2129;
            vertical-align: middle;

            &:nth-child(1) {
              width: 3px;
              height: 16px;
              margin-right: 8px;
              background: #165dff;
            }
          }

          .ant-picker {
            position: absolute;
            top: 50%;
            right: 0;
            transform: translateY(-50%);
          }
        }

        .listWrap {
          margin-top: 20px;
          font-size: 0;

          .item {
            display: inline-block;
            width: calc(50% - 8px);
            padding: 24px 24px 12px;
            font-size: 14px;
            color: #4e5969;
            vertical-align: middle;
            background: linear-gradient(180deg, #f6faff 0%, #fff 100%);
            border: 1px solid #e8f1fc;
            border-radius: 8px;

            &:nth-child(1) {
              margin-right: 16px;
            }

            .img {
              display: block;
              width: 32px;
              height: 32px;
              box-shadow: 0 4px 4px #c5d2f6;

              &.updateImg {
                box-shadow: 0 4px 4px #c5f6db;
              }
            }

            p {
              margin-top: 8px;

              &:nth-of-type(1) {
                margin-bottom: 4px;

                span {
                  display: inline-block;
                  vertical-align: middle;

                  &:nth-child(2) {
                    margin-left: 5px;
                  }
                }
              }
            }

            .ant-statistic {
              ::v-deep(.ant-statistic-content-value-int) {
                font-size: 30px;
                font-weight: 700;
                color: #1d2129;
              }
            }
          }
        }
      }
    }

    .executeContent {
      height: calc(100% - 266px);
      margin-top: 16px;
      background: #fff;
      border-radius: 8px;

      .executeWrap {
        height: 100%;
        padding: 24px;
        overflow: auto;

        .title {
          position: relative;
          font-size: 0;

          p {
            display: inline-block;
            margin: 0;
            font-size: 18px;
            font-weight: 700;
            color: #1d2129;
            vertical-align: middle;

            &:nth-child(1) {
              width: 3px;
              height: 16px;
              margin-right: 8px;
              background: #165dff;
            }
          }

          .anticon {
            display: inline-block;
            margin-left: 5px;
            font-size: 14px;
            color: #4e5969;
            vertical-align: middle;
          }

          .ant-picker {
            position: absolute;
            top: 50%;
            right: 0;
            transform: translateY(-50%);
          }
        }

        .executeList {
          margin-top: 20px;
          font-size: 0;

          .item {
            display: inline-block;
            width: calc(50% - 8px);
            padding: 24px 0;
            font-size: 14px;
            color: #4e5969;
            text-align: center;
            vertical-align: middle;
            background: #fbfdff;
            border: 1px solid #e8f2ff;
            border-radius: 4px;

            &:nth-child(1) {
              margin-right: 16px;
            }

            .img {
              display: inline-block;
              width: 48px;
              height: 48px;
              vertical-align: middle;
              box-shadow: 0 4px 4px #cbe5f9;
            }

            p {
              display: inline-block;
              margin: 0;
              margin-left: 16px;
              text-align: left;
              vertical-align: middle;

              span {
                &:nth-child(1) {
                  display: block;
                  font-size: 30px;
                  font-weight: 700;
                  color: #1d2129;
                  text-align: center;

                  i {
                    display: inline-block;
                    font-style: normal;
                    vertical-align: baseline;

                    &:nth-child(1) {
                      font-size: 30px;
                      font-weight: 700;
                      color: #1d2129;
                    }
                  }
                }
              }
            }
          }
        }

        .list {
          font-size: 0;

          .item {
            display: inline-block;
            width: calc(33.3% - 10px);
            margin-top: 16px;
            margin-left: 15px;
            font-size: 14px;
            color: #4e5969;
            background: #f7f8fa;
            border: 1px solid #e5e6eb;
            border-radius: 4px;

            &:nth-child(3n + 1) {
              margin-left: 0;
            }

            .top {
              padding: 16px 0;
              margin: 0 16px;
              border-bottom: 1px solid #e5e6eb;

              .img {
                display: inline-block;
                width: 18px;
                height: 18px;
                vertical-align: middle;
              }

              p {
                display: inline-block;
                margin: 0;
                margin-left: 8px;
                font-weight: 700;
                color: #1d2129;
                vertical-align: middle;
              }
            }

            .min {
              padding: 16px;

              p {
                display: inline-block;
                width: calc(50% - 4px);
                margin: 0;
                text-align: center;

                span {
                  display: inline-block;

                  &:nth-child(1) {
                    display: block;
                    overflow: hidden;
                    font-size: 24px;
                    font-weight: 700;
                    color: #1d2129;
                    text-overflow: ellipsis;
                    white-space: nowrap;
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
</style>
